package com.hhh.springai_test.controller;

import com.hhh.springai_test.common.BaseResponse;
import com.hhh.springai_test.common.ResultUtils;
import com.hhh.springai_test.constant.UserConstant;
import com.hhh.springai_test.model.dto.communityCategory.AddCommunityCategoryDTO;
import com.hhh.springai_test.model.dto.communityCategory.UpdateCommunityCategoryDTO;
import com.hhh.springai_test.model.po.CommunityCategory;
import com.hhh.springai_test.service.CommunityCategoryService;
import cn.dev33.satoken.annotation.SaCheckRole;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/communityCategory")
public class CommunityCategoryController {

    @Resource
    private CommunityCategoryService communityCategoryService;

    @PostMapping("/add")
    @SaCheckRole(UserConstant.ADMIN_ROLE)
    public BaseResponse<Long> addCategory(@RequestBody AddCommunityCategoryDTO addCommunityCategoryDTO) {
        Long categoryId = communityCategoryService.addCategory(addCommunityCategoryDTO);
        return ResultUtils.success(categoryId);
    }

    @PostMapping("/delete/{id}")
    @SaCheckRole(UserConstant.ADMIN_ROLE)
    public BaseResponse<Boolean> deleteCategory(@PathVariable Long id) {
        boolean result = communityCategoryService.deleteCategory(id);
        return ResultUtils.success(result);
    }

    @PostMapping("/update")
    @SaCheckRole(UserConstant.ADMIN_ROLE)
    public BaseResponse<Boolean> updateCategory(@RequestBody UpdateCommunityCategoryDTO updateCommunityCategoryDTO) {
        boolean result = communityCategoryService.updateCategory(updateCommunityCategoryDTO);
        return ResultUtils.success(result);
    }

    @GetMapping("/list")
    public BaseResponse<List<CommunityCategory>> listCategories() {
        List<CommunityCategory> categories = communityCategoryService.listCategories();
        return ResultUtils.success(categories);
    }
}
